package cn.wolfcode.wolf2w.redis.util;

import cn.wolfcode.wolf2w.util.Consts;
import lombok.Getter;

/**
 *  redis key管理
 *  约定:一个枚举实例就是一个key
 */
@Getter
public enum RedisKeys {

    //接口防刷
    BRUSH_PROOF("brush_proof",-1L),

    //用户攻略点赞
    USER_STRATEGY_THUMBUP("user_strategy_thumbup", -1L),

    //用户攻略收藏
    USER_STRATEGY_FAVOR("user_strategy_favor",-1L),

    //攻略统计对象
    STRATEGY_STATIS_VO("strategy_statis_vo",-1L),

    //短信验证码
    VERIFY_CODE("verify_code",Consts.VERIFY_CODE_VAI_TIME * 60L),
    //登录令牌
    USER_LOGIN_TOKEN("user_login_token", Consts.USER_INFO_TOKEN_VAI_TIME * 60L);

    private String prefix;//key的前缀
    private Long time;//key的有效时间,默认值如果为-1表示不需要指定过期时间

    private RedisKeys(String prefix, Long time){
        this.prefix = prefix;
        this.time = time;
    }

    //拼接完整的key
    public String join(String ...values){
        StringBuilder sb = new StringBuilder();

        sb.append(this.prefix);
        for (String value : values) {
            sb.append(":").append(value);
        }
        return sb.toString();
    }
}
